package exam.demo21;

import java.util.Arrays;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] arr1 = new int[n];
        int[] arr2 = new int[m];
        for(int i = 0; i < n; i++) {
            arr1[i] = in.nextInt();
        }
        for(int i = 0; i < m; i++) {
            arr2[i] = in.nextInt();
        }
        Arrays.sort(arr1);
        Arrays.sort(arr2);
        int i = 0;
        int j = 0;
        while(i < n && j < m) {
            if(arr1[i] < arr2[j]) {
                System.out.print(arr1[i] + " ");
                i++;
            } else if (arr1[i] == arr2[j]){
                i++;
            } else {
                System.out.print(arr2[j] + " ");
                j++;
            }
        }
        while(i < n) {
            System.out.print(arr1[i] + " ");
            i++;
        }
        while(j < m) {
            System.out.print(arr2[j] + " ");
            j++;
        }
    }
}
